{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Generate a String With Characters That Have Odd Counts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: generateTheString"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #生成每种字符都是奇数个的字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数 <code>n</code>，请你返回一个含<em> <code>n</code> </em>个字符的字符串，其中每种字符在该字符串中都恰好出现 <strong>奇数次</strong> <em><strong>。</strong></em></p>\n",
    "\n",
    "<p>返回的字符串必须只含小写英文字母。如果存在多个满足题目要求的字符串，则返回其中任意一个即可。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 4\n",
    "<strong>输出：</strong>&quot;pppz&quot;\n",
    "<strong>解释：</strong>&quot;pppz&quot; 是一个满足题目要求的字符串，因为 &#39;p&#39; 出现 3 次，且 &#39;z&#39; 出现 1 次。当然，还有很多其他字符串也满足题目要求，比如：&quot;ohhh&quot; 和 &quot;love&quot;。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 2\n",
    "<strong>输出：</strong>&quot;xy&quot;\n",
    "<strong>解释：</strong>&quot;xy&quot; 是一个满足题目要求的字符串，因为 &#39;x&#39; 和 &#39;y&#39; 各出现 1 次。当然，还有很多其他字符串也满足题目要求，比如：&quot;ag&quot; 和 &quot;ur&quot;。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>n = 7\n",
    "<strong>输出：</strong>&quot;holasss&quot;\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= n &lt;= 500</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [generate-a-string-with-characters-that-have-odd-counts](https://leetcode.cn/problems/generate-a-string-with-characters-that-have-odd-counts/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [generate-a-string-with-characters-that-have-odd-counts](https://leetcode.cn/problems/generate-a-string-with-characters-that-have-odd-counts/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['4', '2', '7']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a' * (n - 1) + 'b'\n",
    "        else:\n",
    "            return 'a' * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2!=0:\n",
    "            return 'a'*n\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n==1:\n",
    "            return 'a'\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'ab'+'c'*(n-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n == 1:\n",
    "            return 'x'\n",
    "        if n % 2 == 0:\n",
    "            return 'x'*(n-1) + 'y'\n",
    "        else:\n",
    "            return 'x'*(n-2) + 'y' + 'p'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2 == 0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 1:\n",
    "            return \"a\"*n\n",
    "        else:\n",
    "            return \"a\"*(n-1)+\"b\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0:\n",
    "            return \"a\"+\"b\"*(n-1)\n",
    "        else:\n",
    "            return \"a\"*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a' * (n - 1) + 'b'\n",
    "        else :\n",
    "            return 'a' * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*n if n%2 else 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n<=1:\n",
    "            return n*'x'\n",
    "        elif n%2==0:\n",
    "            return (n-1)*'x'+'y'\n",
    "        else:\n",
    "            return n*'x'        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        a = \"a\"\n",
    "        b = \"b\"\n",
    "        s = \"\"\n",
    "        if n%2 == 1:\n",
    "            for i in range(n):\n",
    "                s += a\n",
    "            return s\n",
    "        else:\n",
    "            for i in range(n-1):\n",
    "                s += a\n",
    "            s += b\n",
    "            return s\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a'*(n-1) + 'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            ans = 'b'\n",
    "            n -= 1\n",
    "        else:\n",
    "            ans = ''\n",
    "        return ans + 'a' * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==1:\n",
    "            return 'x'*n\n",
    "        else:\n",
    "            return 'x'*(n-1)+'y'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return \"a\" * (n  - 1) + \"b\" if n % 2 == 0 else \"a\" * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n & 1:\n",
    "            return 'a' * n\n",
    "        return 'b' + 'a' * (n-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0 :\n",
    "            return 'a' * (n-1) + 'b'\n",
    "        if n==2:\n",
    "            return 'ab'\n",
    "        if n==1:\n",
    "            return 'a'\n",
    "        if n%2 != 0:\n",
    "            return 'ab' +'c' * (n-2)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return \"a\"+\"b\"*(n-1)\n",
    "        else:\n",
    "            return \"a\"*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "\n",
    "\n",
    "        a = 'a'\n",
    "        b = 'b'\n",
    "        c = 'c'\n",
    "\n",
    "        if n % 2 == 0:\n",
    "            date = n // 2\n",
    "            if date % 2 == 0:\n",
    "                return a * (date + 1) + b * (n - date - 1)\n",
    "            else:\n",
    "                return a * date + b * date\n",
    "\n",
    "        else:\n",
    "            return a * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 1:\n",
    "            return 'a' * n\n",
    "        else :\n",
    "            return 'a' * (n -1 ) + 'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2 == 0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        result = bytearray()\n",
    "        if n % 2:\n",
    "            result.extend(97 for i in range(n))\n",
    "        else:\n",
    "            result.append(97)\n",
    "            result.extend(98 for i in range(n-1))\n",
    "        return result.decode('ascii')\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        res=''\n",
    "        if n%2!=0:\n",
    "            for i in range(n):\n",
    "                res+='a'\n",
    "        else:\n",
    "            for i in range(n-1):\n",
    "                res+='a'\n",
    "            res+='b'\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        res = \"\"\n",
    "        if n%2 == 0:\n",
    "            return \"a\"*(n-1) + \"b\"\n",
    "        else:\n",
    "            return \"a\"*n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2!=0:return 'a'*n\n",
    "        else:return 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*(n-1)+'b' if n%2==0 else 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==1:\n",
    "            res='a'*n\n",
    "        else:\n",
    "            res='a'*(n-1)+'b'\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*n if n%2==1 else 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n==1:\n",
    "            return 'a'\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*(n-2)+'b'+'c'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        \n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n == 1:\n",
    "            ans = ['a']\n",
    "        elif n%2 == 0:\n",
    "            ans = ['a']*(n-1)\n",
    "            ans.append('b')\n",
    "        else:\n",
    "            ans = ['a']*(n-2)\n",
    "            ans.append('b')\n",
    "            ans.append('c')\n",
    "        return ''.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2 == 0: \n",
    "            return('a'*(n-1) + 'b')\n",
    "        else:\n",
    "            return('a'*n)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return \"a\" * n if n % 2 != 0 else \"a\" * (n - 1) + \"b\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        ans = ''\n",
    "        if n%2 != 0:\n",
    "            for i in range(n):\n",
    "                ans += 's'\n",
    "        else :\n",
    "            for i in range(n-1):\n",
    "                ans += 't'\n",
    "        return ans if n%2 != 0 else ans+'s'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return \"a\"*(n-1) + \"b\"\n",
    "        else:\n",
    "            return \"a\"*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 1:\n",
    "            return \"a\" * n\n",
    "        return \"a\" * (n - 1) + \"b\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n == 1:\n",
    "            return \"a\"\n",
    "        if n%2 == 0:\n",
    "            return \"a\"*(n-1)+\"b\"\n",
    "        return \"a\"*(n-2)+\"bc\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*n if n%2==1 else 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2!=0:\n",
    "            return 'a'*n\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2 == 0:\n",
    "            print('asdsadas')\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*n if n%2==1 else 'a'*(n-1)+'b'\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        result = bytearray()\n",
    "        if n % 2:\n",
    "            result.extend(97 for i in range(n))\n",
    "            return result.decode('ascii')\n",
    "        x = n // 2\n",
    "        if x % 2:\n",
    "            result.extend(97 for i in range(x))\n",
    "            result.extend(98 for i in range(x))\n",
    "        else:\n",
    "            result.extend(97 for i in range(x-1))\n",
    "            result.extend(98 for i in range(x+1))\n",
    "        return result.decode('ascii')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        s=''\n",
    "        if n%2==0:\n",
    "            s=s+'a'*(n-1)\n",
    "            s+='b'\n",
    "            return s\n",
    "        else:\n",
    "            s=s+'a'*n\n",
    "            return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        dic = {}\n",
    "        if n%2 == 0:\n",
    "            dic['a'] = 1\n",
    "            dic['b'] = n - 1\n",
    "        else:\n",
    "            dic['a'] = n\n",
    "        ans = \"\"\n",
    "        for letter, cnt in dic.items():\n",
    "            while cnt != 0:\n",
    "                ans += letter\n",
    "                cnt -= 1 \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        ans = 's'\n",
    "        if n%2 != 0:\n",
    "            ans *= n\n",
    "        else :\n",
    "            ans *= (n-1)\n",
    "            ans += 't'\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*n if n%2 else 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        # 如果n是奇数，就生成n个a，否则就n-1个a和一个b\n",
    "        \n",
    "        return \"a\"*n if n%2==1 else \"a\"*(n-1)+\"b\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import random\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0:\n",
    "            return  'a'+'b'*(n-1)\n",
    "        else:\n",
    "            return 'a'*n\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 != 0:\n",
    "            return \"a\" * n\n",
    "        return \"a\" * (n - 1) + \"b\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n == 1:\n",
    "            return 'm'\n",
    "        elif n == 2:\n",
    "            return 'mn'\n",
    "        elif n%2 == 0:\n",
    "            return 'n'+'m'*(n-1)\n",
    "        else:\n",
    "            return 'p'+ self.generateTheString(n-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        res = ''\n",
    "        if n % 2 == 0:\n",
    "            for i in range(n-1):\n",
    "                res += 'a'\n",
    "            res += 'b'\n",
    "        else:\n",
    "            for i in range(n):\n",
    "                res += 'a'\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2:\n",
    "            return \"a\" * n\n",
    "        else:\n",
    "            return \"a\" * (n - 1) + \"b\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a'*(n-1) + 'b'\n",
    "        else:\n",
    "            return 'a'*n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n==1:\n",
    "            return 'a'\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a' + 'b' * (n - 1)\n",
    "        return 'a' * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2 == 0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a' * (n-1) + 'm'\n",
    "        return 'z' * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2!=0:\n",
    "            return 'a'*n\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n %2 ==1:\n",
    "            return \"a\" *n\n",
    "        return \"a\" * (n-1)+\"b\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2:\n",
    "            return 'a' * n\n",
    "        return 'a' + 'b'*(n-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        pr = ''\n",
    "        if n % 2 == 0 :\n",
    "            for i in range(n-1):\n",
    "                pr += 'x'\n",
    "            pr += 'y'\n",
    "        else :\n",
    "            for k in range(n) :\n",
    "                pr += 'x'\n",
    "        return pr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        return 'a'*n if n%2 else 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return \"a\"+\"\".join([\"b\" for x in range(n-1)])\n",
    "        else:\n",
    "            return \"\".join([\"a\" for x in range(n)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a' * (n-1) + 'b'\n",
    "        return 'b' * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n %2 == 0:\n",
    "            return \"a\" * (n-1) + \"b\"\n",
    "        else:\n",
    "            return \"a\" * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        s = \"sb\"\n",
    "        if n % 2 == 0:\n",
    "            return s[0] * (n-1) + s[1]\n",
    "\n",
    "        else:\n",
    "            return s[0] * n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        # dic = {}\n",
    "        # if n%2 == 0:\n",
    "        #     dic['a'] = 1\n",
    "        #     dic['b'] = n - 1\n",
    "        # else:\n",
    "        #     dic['a'] = n\n",
    "        # ans = \"\"\n",
    "        # for letter, cnt in dic.items():\n",
    "        #     while cnt != 0:\n",
    "        #         ans += letter\n",
    "        #         cnt -= 1 \n",
    "        # return ans\n",
    "        if n % 2 == 1:\n",
    "            return \"a\" * n\n",
    "        return \"a\" * (n-1) + \"b\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2==0:\n",
    "            return 'a'*(n-1)+'b'\n",
    "        else:\n",
    "            return 'a'*n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n%2:\n",
    "            return 'a'*n\n",
    "        else:\n",
    "            return 'a'*(n-1)+'b'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 1:\n",
    "            return ''.join(['a' * n])\n",
    "        else:\n",
    "            return ''.join(['a' * (n-1),'b'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generateTheString(self, n: int) -> str:\n",
    "        if n % 2 == 0:\n",
    "            return 'a' * (n-1) + 'm'\n",
    "        return 'z' * n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
